//
//  videoViewController.m
//  testassembly
//
//  Created by liangang on 2018/3/28.
//  Copyright © 2018年 liangang. All rights reserved.
//

#import "videoViewController.h"
#import "ZFPlayer.h"
#import "getVideoDetailApi.h"
@interface videoViewController ()

@end

@implementation videoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    getVideoDetailApi *api = [[getVideoDetailApi alloc]init];
    api.videoId  = self.videoId;
//    self.webView.scrollView.bounces  = NO;
    
    // delegate
    //        self.playerView.delegate = self;
    // auto play the video
    self.automaticallyAdjustsScrollViewInsets   = NO;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStyleDone target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://www.lialoan.com/Driver/play.html?id=%@",self.videoId]]]];
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest *request) {
        NSLog(@"%@",request.responseString  );
        NSString *vidoeUrl = [NSString stringWithFormat:@"https://www.lialoan.com/DriverApp/%@",request.responseJSONObject[@"data"][@"video_url"]];
        ZFPlayerView *playerView = [ZFPlayerView new];
        [self.videoBgView addSubview:playerView];
        [playerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.equalTo(playerView.superview );
        }];
        playerView.backgroundColor = [UIColor blueColor];
        ZFPlayerControlView *controlView = [[ZFPlayerControlView alloc] init];
        // model
        ZFPlayerModel *playerModel = [[ZFPlayerModel alloc] init];
        playerModel.fatherView = self.videoBgView;
        playerModel.videoURL = [NSURL URLWithString:vidoeUrl];
        playerModel.title = request.responseJSONObject[@"data"][@"video_title"];
        self.title =request.responseJSONObject[@"data"][@"video_title"];
        playerModel.placeholderImageURLString = [NSString stringWithFormat:@"https://www.lialoan.com/DriverApp/%@",request.responseJSONObject[@"data"][@"video_thumbnail"]];
        
        [playerView playerControlView:controlView playerModel:playerModel];
        
        [playerView autoPlayTheVideo];
        
       
    } failure:^(__kindof YTKBaseRequest *request) {
        
    }];
    // Do any additional setup after loading the view from its nib.
}
-(void)back
{
    [self.navigationController   popViewControllerAnimated:YES];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden= NO;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
